<template>
  <el-card class="cardClass">
    <div slot="header" class="cardClass_header">
      <h3>未入罐奶量记录</h3>
      <div>
        <el-button
          size="mini"
          type="success"
          icon="el-icon-plus"
          @click="open('新增奶量记录')"
          >新增</el-button
        >
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-search"
          @click="searchHidden()"
          >搜索</el-button
        >
      </div>
    </div>
    <!-- 查询表单 -->
    <el-collapse-transition>
      <el-form
        :model="ruleForm"
        :inline="true"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        v-if="hidden"
      >
        <el-form-item label="字段：" prop="key">
          <el-select
            v-model="ruleForm.key"
            placeholder="请选择查询字段"
            size="small"
            @change="change"
          >
            <el-option
              v-for="item in keyOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="值：" prop="value">
          <el-select
            v-model="ruleForm.value"
            placeholder="请选择"
            v-show="selectshow != 0"
            size="small"
          >
            <el-option
              v-for="item in options"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
          <el-input
            v-model="ruleForm.value"
            placeholder="请输入值"
            size="small"
            clearable
            v-show="selectshow != 1"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            size="small"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button
            @click="resetForm('ruleForm')"
            size="small"
            icon="el-icon-refresh"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-collapse-transition>
    <!-- 表格 -->
    <el-table
      :data="tableData"
      stripe
      v-loading="loading"
      size="small"
      border
      style="width: 100%"
    >
      <el-table-column prop="guanlihao" label="管理号" align="center">
        
      </el-table-column>
      <el-table-column
        prop="niuzhishuliang"
        label="牛只数量"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="zongnailiang"
        label="总奶量（L）"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="weiruguannai"
        label="未入罐奶量"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
            <el-button
            type="warning"
            size="mini"
            icon="el-icon-edit"
            @click="open('修改奶量记录', scope.row)"
            >修改</el-button
          >
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="del(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="total, prev, pager, next, jumper"
      
      :total="total"
      :page-size="ruleForm.pageSize"
      v-show="!loading"
      :current-page="ruleForm.pageNum"
      @current-change="changePage"
      class="pageClass"
    ></el-pagination>
    <adduntappedMilk ref="adduntappedMilkref"></adduntappedMilk>
  </el-card>
</template>
  
  <script>
import {
  queryuntappedmilk,
  deleteuntappedmilk,
} from "@/apis/sales/untappedMilk.js";
import adduntappedMilk from '@/components/sales/adduntappedMilk';
export default {
  name: "storeManagement",
  components: {
    adduntappedMilk
  },
  provide() {
    return {
      search: this.search,
    };
  },
  data() {
    return {
      loading: false,
      hidden: false,
      total: null,
      ruleForm: {
        key: "guanlihao",
        value: "",
        pageNum: 1,
        pageSize: 5,
      },
      keyOptions: [
        { value: "guanlihao", label: "管理号" },
        { value: "zongnailiang", label: "总奶量" },
      ],
      rules: {
        key: [{ required: true, message: "请选择查询字段", trigger: "blur" }],
      },
      tableData: [
      ],
    };
  },
  created() {
    this.search();
  },
  methods: {
    // 新增/修改弹窗
    open(title, row) {
     this.$refs.adduntappedMilkref.show(title, row);
    },
    // 搜索隐藏
    searchHidden() {
      this.hidden = !this.hidden;
    },
    // 搜索方法
    search() {
      const _this = this;
      _this.loading = true;
      queryuntappedmilk(_this.ruleForm).then((res) => {
        console.log(res);
        _this.tableData = res.data;
        _this.total = res.total;
        _this.loading = false;
      });
    },
    // 搜索
    submitForm(formName) {
      // console.log(this.ruleForm);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.search();
          this.ruleForm.pageNum = 1; // 查询重置页数
        }
      });
    },
    // 分页
    changePage(pageNum) {
      this.ruleForm.pageNum = pageNum;
      this.search();
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.search();
      this.ruleForm.pageNum = 1; // 查询重置页数
    },
    // 展开详情
    expandChange(row, rowList) {
      var _this = this;
      if (rowList.length) {
        _this.expands = [];
        if (row) {
          _this.expands.push(row.recordOrder);
          setTimeout(() => {
            _this.$refs["detailsSalesRef"].getData(row);
          }, 1);
        }
        //  this.tablaData(row.eqId)  这里可以调用接口数据渲染
      } else {
        _this.expands = [];
      }
    },
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    // 删除
    del(row) {
      // console.log(row);
      const _this = this;
      _this
        .$confirm("确认删除此条记录“" + row.recordOrder + "”吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          deleteuntappedmilk(row.recordOrder).then(function (res) {
            if (res.code === 0) {
              _this.$message({
                type: "success",
                message: "员工出售记录“" + row.recordOrder + "”" + res.msg,
              });
              _this.search();
              _this.ruleForm.pageNum = 1; // 查询重置页数
            } else {
              _this.$message({
                type: "warning",
                message: "员工出售记录" + row.recordOrder + "”" + res.msg,
              });
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
  
  <style scoped></style>